﻿@model AddressListModel
@{
    ViewBag.Title = "地址列表展示";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<section class="layui-larry-box">
    <div class="larry-personal">
        <div class="layui-tab">
            <blockquote class="layui-elem-quote address_search">
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-normal addressAdd_btn">添加收货地址</a>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-danger batchDel">批量删除</a>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-mid layui-word-aux">本页面刷新后除新添加的文章外所有操作无效，关闭页面所有数据重置</div>
                </div>
                <div class="layui-inline">
                    <span class="layui-form-mid">共有<span style="font-weight: bold">@Model.TotalCount</span>条数据</span>
                </div>
            </blockquote>

            <!-- 操作日志 -->
            <div class="layui-form address_list">
                <table class="layui-table">
                    <colgroup>
                        <col width="10%">
                        <col>
                        <col>
                        <col>
                        <col>
                        <col>
                        <col>
                        <col>
                        <col>
                    </colgroup>
                    <thead>
                        <tr>
                            <th>
                                <input name="" lay-skin="primary" lay-filter="allChoose" id="allChoose" type="checkbox">
                                <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                    <i class="layui-icon"></i>
                                </div>
                            </th>
                            <th>收货人</th>
                            <th>购买人</th>
                            <th>收货人电话</th>
                            <th>收货地址</th>
                            <th>具体小区地址</th>
                            <th>邮编号</th>
                            <th>添加该收货地址时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    @foreach (var address in Model.AddressDTO)
                    {
                        <tbody class="address_content">
                            <tr>
                                <td>
                                    <input name="checked" lay-skin="primary" lay-filter="choose" type="checkbox">
                                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                        <i class="layui-icon"></i>
                                    </div>
                                </td>
                                <th>@address.UserName</th>
                                <th>@address.PhoneNum</th>
                                <th>@(address.ProvinceName + address.CityName + address.AreaName)</th>
                                <th>@address.Adress</th>
                                <th>@address.PostEmail</th>
                                <th>@address.CreateDateTime</th>

                                <td>
                                    <a class="layui-btn layui-btn-mini address_edit" data-id="@address.Id">
                                    <i class="iconfont icon-edit"></i> 编辑</a>
                                    <a class="layui-btn layui-btn-danger layui-btn-mini address_del" data-id="@address.Id">
                                        <i class="layui-icon"></i> 删除
                                    </a>
                                </td>
                            </tr>

                        </tbody>
                    }
                </table>
                <div class="larry-table-page clearfix">
                    <div id="page" class="page">@Html.Raw(Model.PageStr)</div>
                </div>
            </div>

        </div>
    </div>
    @section FooterScript{
        <script type="text/javascript">

            var appConfig = {
                name: "address",    //需要和页面名称对应
                title: "收货地址",    //显示的名称
                addUrl: "AddNew",   //添加弹框的路径
                editUrl: "Edit?id=",      //修改弹框的路径
                $: "",
                layer: "",

                //批量删除Ajax
                batchDel: function (data) {     //Array data 得到的是 需要删除的id
                    data.each(function (index, value) {
                        console.log(value);

                        //todo:在此处添加批量删除记录的ajax

                    });

                },
                del: function (data) {

                    console.log(data);
                    $ = appConfig.$;

                    $.ajax({
                        url: "/Address/Delete",
                        type: "post",
                        dataType: "json",
                        data: { id: data },
                        success: function (res) {
                            if (res.status == "ok") {
                                appConfig.layer.msg("删除成功", { time: 1000, icon: 1 });
                            } else if (res.status == "redirect") {
                                location.href = res.msg;
                            } else {
                                appConfig.layer.msg("错误", { time: 1000,icon:2 });
                            }
                        }
                    });
                    //todo:在此处添加删除记录的ajax
                }
            };

            layui.use(['jquery', 'layer', 'element', 'laypage'], function () {
                window.jQuery = window.$ = layui.jquery;
                window.layer = layui.layer;
                var element = layui.element(),
                    laypage = layui.laypage;


                //laypage({
                //    cont: 'page',
                //    pages: 10 //总页数
                //    ,
                //    groups: 5 //连续显示分页数
                //    ,
                //    jump: function (obj, first) {
                //        //得到了当前页，用于向服务端请求对应数据
                //        var curr = obj.curr;
                //        if (!first) {
                //            //layer.msg('第 '+ obj.curr +' 页');
                //        }
                //    }
                //});

            });
        </script>
    }

